package torque.generated;


import java.math.BigDecimal;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;

import org.apache.commons.lang.ObjectUtils;
import org.apache.torque.TorqueException;
import org.apache.torque.map.TableMap;
import org.apache.torque.om.BaseObject;
import org.apache.torque.om.ComboKey;
import org.apache.torque.om.DateKey;
import org.apache.torque.om.NumberKey;
import org.apache.torque.om.ObjectKey;
import org.apache.torque.om.SimpleKey;
import org.apache.torque.om.StringKey;
import org.apache.torque.om.Persistent;
import org.apache.torque.util.Criteria;
import org.apache.torque.util.Transaction;





/**
 * Inventaire
 *
 * This class was autogenerated by Torque on:
 *
 * [Thu Oct 17 18:54:08 CEST 2013]
 *
 * You should not use this class directly.  It should not even be
 * extended all references should be to Inventaireequipement
 */
public abstract class BaseInventaireequipement extends BaseObject
{
    /** Serial version */
    private static final long serialVersionUID = 1382028848659L;

    /** The Peer class */
    private static final InventaireequipementPeer peer =
        new InventaireequipementPeer();


    /** The value for the pseudotroll field */
    private String pseudotroll;

    /** The value for the idinvequip field */
    private int idinvequip;

    /** The value for the nomobjet field */
    private String nomobjet;


    /**
     * Get the Pseudotroll
     *
     * @return String
     */
    public String getPseudotroll()
    {
        return pseudotroll;
    }


    /**
     * Set the value of Pseudotroll
     *
     * @param v new value
     */
    public void setPseudotroll(String v) throws TorqueException
    {

        if (!ObjectUtils.equals(this.pseudotroll, v))
        {
            this.pseudotroll = v;
            setModified(true);
        }


        if (aTroll != null && !ObjectUtils.equals(aTroll.getPseudotroll(), v))
        {
            aTroll = null;
        }

    }

    /**
     * Get the Idinvequip
     *
     * @return int
     */
    public int getIdinvequip()
    {
        return idinvequip;
    }


    /**
     * Set the value of Idinvequip
     *
     * @param v new value
     */
    public void setIdinvequip(int v) 
    {

        if (this.idinvequip != v)
        {
            this.idinvequip = v;
            setModified(true);
        }


    }

    /**
     * Get the Nomobjet
     *
     * @return String
     */
    public String getNomobjet()
    {
        return nomobjet;
    }


    /**
     * Set the value of Nomobjet
     *
     * @param v new value
     */
    public void setNomobjet(String v) throws TorqueException
    {

        if (!ObjectUtils.equals(this.nomobjet, v))
        {
            this.nomobjet = v;
            setModified(true);
        }


        if (aObjet != null && !ObjectUtils.equals(aObjet.getNomobjet(), v))
        {
            aObjet = null;
        }

    }

    



    private Troll aTroll;

    /**
     * Declares an association between this object and a Troll object
     *
     * @param v Troll
     * @throws TorqueException
     */
    public void setTroll(Troll v) throws TorqueException
    {
        if (v == null)
        {
            setPseudotroll((String) null);
        }
        else
        {
            setPseudotroll(v.getPseudotroll());
        }
        aTroll = v;
    }


    /**
     * Returns the associated Troll object.
     * If it was not retrieved before, the object is retrieved from
     * the database
     *
     * @return the associated Troll object
     * @throws TorqueException
     */
    public Troll getTroll()
        throws TorqueException
    {
        if (aTroll == null && (!ObjectUtils.equals(this.pseudotroll, null)))
        {
            aTroll = TrollPeer.retrieveByPK(SimpleKey.keyFor(this.pseudotroll));
        }
        return aTroll;
    }

    /**
     * Return the associated Troll object
     * If it was not retrieved before, the object is retrieved from
     * the database using the passed connection
     *
     * @param connection the connection used to retrieve the associated object
     *        from the database, if it was not retrieved before
     * @return the associated Troll object
     * @throws TorqueException
     */
    public Troll getTroll(Connection connection)
        throws TorqueException
    {
        if (aTroll == null && (!ObjectUtils.equals(this.pseudotroll, null)))
        {
            aTroll = TrollPeer.retrieveByPK(SimpleKey.keyFor(this.pseudotroll), connection);
        }
        return aTroll;
    }

    /**
     * Provides convenient way to set a relationship based on a
     * ObjectKey, for example
     * <code>bar.setFooKey(foo.getPrimaryKey())</code>
     *
     */
    public void setTrollKey(ObjectKey key) throws TorqueException
    {

        setPseudotroll(key.toString());
    }




    private Objet aObjet;

    /**
     * Declares an association between this object and a Objet object
     *
     * @param v Objet
     * @throws TorqueException
     */
    public void setObjet(Objet v) throws TorqueException
    {
        if (v == null)
        {
            setNomobjet((String) null);
        }
        else
        {
            setNomobjet(v.getNomobjet());
        }
        aObjet = v;
    }


    /**
     * Returns the associated Objet object.
     * If it was not retrieved before, the object is retrieved from
     * the database
     *
     * @return the associated Objet object
     * @throws TorqueException
     */
    public Objet getObjet()
        throws TorqueException
    {
        if (aObjet == null && (!ObjectUtils.equals(this.nomobjet, null)))
        {
            aObjet = ObjetPeer.retrieveByPK(SimpleKey.keyFor(this.nomobjet));
        }
        return aObjet;
    }

    /**
     * Return the associated Objet object
     * If it was not retrieved before, the object is retrieved from
     * the database using the passed connection
     *
     * @param connection the connection used to retrieve the associated object
     *        from the database, if it was not retrieved before
     * @return the associated Objet object
     * @throws TorqueException
     */
    public Objet getObjet(Connection connection)
        throws TorqueException
    {
        if (aObjet == null && (!ObjectUtils.equals(this.nomobjet, null)))
        {
            aObjet = ObjetPeer.retrieveByPK(SimpleKey.keyFor(this.nomobjet), connection);
        }
        return aObjet;
    }

    /**
     * Provides convenient way to set a relationship based on a
     * ObjectKey, for example
     * <code>bar.setFooKey(foo.getPrimaryKey())</code>
     *
     */
    public void setObjetKey(ObjectKey key) throws TorqueException
    {

        setNomobjet(key.toString());
    }
   
        
    private static List fieldNames = null;

    /**
     * Generate a list of field names.
     *
     * @return a list of field names
     */
    public static synchronized List getFieldNames()
    {
        if (fieldNames == null)
        {
            fieldNames = new ArrayList();
            fieldNames.add("Pseudotroll");
            fieldNames.add("Idinvequip");
            fieldNames.add("Nomobjet");
            fieldNames = Collections.unmodifiableList(fieldNames);
        }
        return fieldNames;
    }

    /**
     * Retrieves a field from the object by field (Java) name passed in as a String.
     *
     * @param name field name
     * @return value
     */
    public Object getByName(String name)
    {
        if (name.equals("Pseudotroll"))
        {
            return getPseudotroll();
        }
        if (name.equals("Idinvequip"))
        {
            return new Integer(getIdinvequip());
        }
        if (name.equals("Nomobjet"))
        {
            return getNomobjet();
        }
        return null;
    }

    /**
     * Set a field in the object by field (Java) name.
     *
     * @param name field name
     * @param value field value
     * @return True if value was set, false if not (invalid name / protected field).
     * @throws IllegalArgumentException if object type of value does not match field object type.
     * @throws TorqueException If a problem occurs with the set[Field] method.
     */
    public boolean setByName(String name, Object value )
        throws TorqueException, IllegalArgumentException
    {
        if (name.equals("Pseudotroll"))
        {
            // Object fields can be null
            if (value != null && ! String.class.isInstance(value))
            {
                throw new IllegalArgumentException("Invalid type of object specified for value in setByName");
            }
            setPseudotroll((String) value);
            return true;
        }
        if (name.equals("Idinvequip"))
        {
            if (value == null || ! (Integer.class.isInstance(value)))
            {
                throw new IllegalArgumentException("setByName: value parameter was null or not an Integer object.");
            }
            setIdinvequip(((Integer) value).intValue());
            return true;
        }
        if (name.equals("Nomobjet"))
        {
            // Object fields can be null
            if (value != null && ! String.class.isInstance(value))
            {
                throw new IllegalArgumentException("Invalid type of object specified for value in setByName");
            }
            setNomobjet((String) value);
            return true;
        }
        return false;
    }

    /**
     * Retrieves a field from the object by name passed in
     * as a String.  The String must be one of the static
     * Strings defined in this Class' Peer.
     *
     * @param name peer name
     * @return value
     */
    public Object getByPeerName(String name)
    {
        if (name.equals(InventaireequipementPeer.PSEUDOTROLL))
        {
            return getPseudotroll();
        }
        if (name.equals(InventaireequipementPeer.IDINVEQUIP))
        {
            return new Integer(getIdinvequip());
        }
        if (name.equals(InventaireequipementPeer.NOMOBJET))
        {
            return getNomobjet();
        }
        return null;
    }

    /**
     * Set field values by Peer Field Name
     *
     * @param name field name
     * @param value field value
     * @return True if value was set, false if not (invalid name / protected field).
     * @throws IllegalArgumentException if object type of value does not match field object type.
     * @throws TorqueException If a problem occurs with the set[Field] method.
     */
    public boolean setByPeerName(String name, Object value)
        throws TorqueException, IllegalArgumentException
    {
      if (InventaireequipementPeer.PSEUDOTROLL.equals(name))
        {
            return setByName("Pseudotroll", value);
        }
      if (InventaireequipementPeer.IDINVEQUIP.equals(name))
        {
            return setByName("Idinvequip", value);
        }
      if (InventaireequipementPeer.NOMOBJET.equals(name))
        {
            return setByName("Nomobjet", value);
        }
        return false;
    }

    /**
     * Retrieves a field from the object by Position as specified
     * in the xml schema.  Zero-based.
     *
     * @param pos position in xml schema
     * @return value
     */
    public Object getByPosition(int pos)
    {
        if (pos == 0)
        {
            return getPseudotroll();
        }
        if (pos == 1)
        {
            return new Integer(getIdinvequip());
        }
        if (pos == 2)
        {
            return getNomobjet();
        }
        return null;
    }

    /**
     * Set field values by its position (zero based) in the XML schema.
     *
     * @param position The field position
     * @param value field value
     * @return True if value was set, false if not (invalid position / protected field).
     * @throws IllegalArgumentException if object type of value does not match field object type.
     * @throws TorqueException If a problem occurs with the set[Field] method.
     */
    public boolean setByPosition(int position, Object value)
        throws TorqueException, IllegalArgumentException
    {
    if (position == 0)
        {
            return setByName("Pseudotroll", value);
        }
    if (position == 1)
        {
            return setByName("Idinvequip", value);
        }
    if (position == 2)
        {
            return setByName("Nomobjet", value);
        }
        return false;
    }
     
    /**
     * Stores the object in the database.  If the object is new,
     * it inserts it; otherwise an update is performed.
     *
     * @throws Exception
     */
    public void save() throws Exception
    {
        save(InventaireequipementPeer.DATABASE_NAME);
    }

    /**
     * Stores the object in the database.  If the object is new,
     * it inserts it; otherwise an update is performed.
     * Note: this code is here because the method body is
     * auto-generated conditionally and therefore needs to be
     * in this file instead of in the super class, BaseObject.
     *
     * @param dbName
     * @throws TorqueException
     */
    public void save(String dbName) throws TorqueException
    {
        Connection con = null;
        try
        {
            con = Transaction.begin(dbName);
            save(con);
            Transaction.commit(con);
        }
        catch(TorqueException e)
        {
            Transaction.safeRollback(con);
            throw e;
        }
    }

    /** flag to prevent endless save loop, if this object is referenced
        by another object which falls in this transaction. */
    private boolean alreadyInSave = false;
    /**
     * Stores the object in the database.  If the object is new,
     * it inserts it; otherwise an update is performed.  This method
     * is meant to be used as part of a transaction, otherwise use
     * the save() method and the connection details will be handled
     * internally
     *
     * @param con
     * @throws TorqueException
     */
    public void save(Connection con) throws TorqueException
    {
        if (!alreadyInSave)
        {
            alreadyInSave = true;



            // If this object has been modified, then save it to the database.
            if (isModified())
            {
                if (isNew())
                {
                    InventaireequipementPeer.doInsert((Inventaireequipement) this, con);
                    setNew(false);
                }
                else
                {
                    InventaireequipementPeer.doUpdate((Inventaireequipement) this, con);
                }
            }

            alreadyInSave = false;
        }
    }



    private final SimpleKey[] pks = new SimpleKey[3];
    private final ComboKey comboPK = new ComboKey(pks);

    /**
     * Set the PrimaryKey with an ObjectKey
     *
     * @param key
     */
    public void setPrimaryKey(ObjectKey key) throws TorqueException
    {
        SimpleKey[] keys = (SimpleKey[]) key.getValue();
        setPseudotroll(keys[0].toString());
        setIdinvequip(((NumberKey)keys[1]).intValue());
        setNomobjet(keys[2].toString());
    }

    /**
     * Set the PrimaryKey using SimpleKeys.
     *
     * @param pseudotroll String
     * @param idinvequip int
     * @param nomobjet String
     */
    public void setPrimaryKey( String pseudotroll, int idinvequip, String nomobjet)
        throws TorqueException
    {
        setPseudotroll(pseudotroll);
        setIdinvequip(idinvequip);
        setNomobjet(nomobjet);
    }

    /**
     * Set the PrimaryKey using a String.
     */
    public void setPrimaryKey(String key) throws TorqueException
    {
        setPrimaryKey(new ComboKey(key));
    }

    /**
     * returns an id that differentiates this object from others
     * of its class.
     */
    public ObjectKey getPrimaryKey()
    {
        pks[0] = SimpleKey.keyFor(getPseudotroll());
        pks[1] = SimpleKey.keyFor(getIdinvequip());
        pks[2] = SimpleKey.keyFor(getNomobjet());
        return comboPK;
    }
 

    /**
     * Makes a copy of this object.
     * It creates a new object filling in the simple attributes.
     * It then fills all the association collections and sets the
     * related objects to isNew=true.
     */
    public Inventaireequipement copy() throws TorqueException
    {
        return copy(true);
    }

    /**
     * Makes a copy of this object using connection.
     * It creates a new object filling in the simple attributes.
     * It then fills all the association collections and sets the
     * related objects to isNew=true.
     *
     * @param con the database connection to read associated objects.
     */
    public Inventaireequipement copy(Connection con) throws TorqueException
    {
        return copy(true, con);
    }

    /**
     * Makes a copy of this object.
     * It creates a new object filling in the simple attributes.
     * If the parameter deepcopy is true, it then fills all the
     * association collections and sets the related objects to
     * isNew=true.
     *
     * @param deepcopy whether to copy the associated objects.
     */
    public Inventaireequipement copy(boolean deepcopy) throws TorqueException
    {
        return copyInto(new Inventaireequipement(), deepcopy);
    }

    /**
     * Makes a copy of this object using connection.
     * It creates a new object filling in the simple attributes.
     * If the parameter deepcopy is true, it then fills all the
     * association collections and sets the related objects to
     * isNew=true.
     *
     * @param deepcopy whether to copy the associated objects.
     * @param con the database connection to read associated objects.
     */
    public Inventaireequipement copy(boolean deepcopy, Connection con) throws TorqueException
    {
        return copyInto(new Inventaireequipement(), deepcopy, con);
    }
  
    /**
     * Fills the copyObj with the contents of this object.
     * The associated objects are also copied and treated as new objects.
     *
     * @param copyObj the object to fill.
     */
    protected Inventaireequipement copyInto(Inventaireequipement copyObj) throws TorqueException
    {
        return copyInto(copyObj, true);
    }

  
    /**
     * Fills the copyObj with the contents of this object using connection.
     * The associated objects are also copied and treated as new objects.
     *
     * @param copyObj the object to fill.
     * @param con the database connection to read associated objects.
     */
    protected Inventaireequipement copyInto(Inventaireequipement copyObj, Connection con) throws TorqueException
    {
        return copyInto(copyObj, true, con);
    }
  
    /**
     * Fills the copyObj with the contents of this object.
     * If deepcopy is true, The associated objects are also copied
     * and treated as new objects.
     *
     * @param copyObj the object to fill.
     * @param deepcopy whether the associated objects should be copied.
     */
    protected Inventaireequipement copyInto(Inventaireequipement copyObj, boolean deepcopy) throws TorqueException
    {
        copyObj.setPseudotroll(pseudotroll);
        copyObj.setIdinvequip(idinvequip);
        copyObj.setNomobjet(nomobjet);

        copyObj.setPseudotroll((String)null);
        copyObj.setIdinvequip( 0);
        copyObj.setNomobjet((String)null);

        if (deepcopy)
        {
        }
        return copyObj;
    }
        
    
    /**
     * Fills the copyObj with the contents of this object using connection.
     * If deepcopy is true, The associated objects are also copied
     * and treated as new objects.
     *
     * @param copyObj the object to fill.
     * @param deepcopy whether the associated objects should be copied.
     * @param con the database connection to read associated objects.
     */
    protected Inventaireequipement copyInto(Inventaireequipement copyObj, boolean deepcopy, Connection con) throws TorqueException
    {
        copyObj.setPseudotroll(pseudotroll);
        copyObj.setIdinvequip(idinvequip);
        copyObj.setNomobjet(nomobjet);

        copyObj.setPseudotroll((String)null);
        copyObj.setIdinvequip( 0);
        copyObj.setNomobjet((String)null);

        if (deepcopy)
        {
        }
        return copyObj;
    }
    
    

    /**
     * returns a peer instance associated with this om.  Since Peer classes
     * are not to have any instance attributes, this method returns the
     * same instance for all member of this class. The method could therefore
     * be static, but this would prevent one from overriding the behavior.
     */
    public InventaireequipementPeer getPeer()
    {
        return peer;
    }

    /**
     * Retrieves the TableMap object related to this Table data without
     * compiler warnings of using getPeer().getTableMap().
     *
     * @return The associated TableMap object.
     */
    public TableMap getTableMap() throws TorqueException
    {
        return InventaireequipementPeer.getTableMap();
    }


    public String toString()
    {
        StringBuffer str = new StringBuffer();
        str.append("Inventaireequipement:\n");
        str.append("Pseudotroll = ")
           .append(getPseudotroll())
           .append("\n");
        str.append("Idinvequip = ")
           .append(getIdinvequip())
           .append("\n");
        str.append("Nomobjet = ")
           .append(getNomobjet())
           .append("\n");
        return(str.toString());
    }
}
